#!/usr/bin/expect
#校验beetle机器用户是否能免密登录远程终端

set timeout 1
set sshIp [lindex $argv 0]
set sshNewUser [lindex $argv 1]
set loginUser [lindex $argv 2]
set port [lindex $argv 3]
#开启子进程
spawn ssh -p ${port} ${sshNewUser}@${sshIp} -i /home/${loginUser}/.Beetle/common_id_rsa
expect "*yes/no*" {send "yes\r"}\
		"*$*" {send "\r"}\
		"*No such file*" { exit 1}\
		"*not known*" { exit 1}\
        "*refused*" { exit 1}
#expect "*$*"
#send "ls -alh\r"
#expect "*$*"
#send "exit"
#结束子进程
expect eof
exit